Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Add a common codeAction method to the presentation compiler together with a supportedCodeActions method #6737

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

KacperFKorban
Copy link
Collaborator

@KacperFKorban KacperFKorban commented Aug 30, 2024

This PR adds two methods to the presentation compiler interface so that adding new code actions will be easier.
The functions are:

  • public CompletableFuture<List<TextEdit>> codeAction(OffsetParams params, String codeActionId, Object codeActionPayload)
  • public List<CodeActionId> supportedCodeActions()

codeAction is supposed to be a common method for executing code actions with the presentation compiler.

supportedCodeActions is a new method that is supposed to allow better handling for code actions that are implemented for only some presentation compilers e.g. only for Scala 3. (Here might be some discussion around whether we can allow some more information to be passed to this functions, so that the result will depend on e.g. the location in the file in addition to the presentation compiler used for the file).

When creating a new code action that needs a new presentation compiler method that fits this interface -- only returns List<TextEdit> the new steps will be:

  • when implementing the code action handler class (the one that extends CodeAction) override its val maybeCodeActionId: Option[String] with Some("TheNewCodeActionIdYouCreated")
  • in your presentation compiler implementation add a new case for your new CodeActionId and handle the code action there.
  • if necessary, create a new class for the code action payload in the shared java sources (try to avoid doing so, since this would also have to be backported to the other presentation compiler implementation (metals -> scala3 or scala3 -> metals)

closes #6265

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks! Should this be out of draft state?

@KacperFKorban KacperFKorban marked this pull request as ready for review September 17, 2024 07:18
@KacperFKorban
Copy link
Collaborator Author

@tgodzik Yes, I think it's ready.

@tgodzik tgodzik merged commit eb2cdb8 into scalameta:main Sep 17, 2024
20 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify adding compiler code actions
2 participants